package com.jh.user.pojo;

import cn.jh.common.utils.CommonConstants;
import com.fasterxml.jackson.annotation.JsonFormat;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Objects;

/**
 * 绑定银行卡
 */
@Entity
@Table(name="t_bank_info")
public class UserBankInfo implements Serializable{

	private static final long serialVersionUID = 1L;



	public static UserBankInfo tramformCardType(UserBankInfo userBankInfo) {
		String cardType = userBankInfo.getCardType();
		if (Objects.equals(CommonConstants.DEBIT_2, cardType)) {
			userBankInfo.setCardType(CommonConstants.DEBIT_CARD);
		} else {
			userBankInfo.setCardType(CommonConstants.CREDIT_CARD);
		}
		return userBankInfo;
	}

	@Id
	@Column(name="id")
	private int id;

	@Column(name="user_id")
	private long userId;

	/**支行名称*/
	@Column(name="bankbranch_name")
	private String bankBranchName;

	/**
	 * 省份
	 */
	@Column(name="province")
	private String province;
	/**
	 * 城市
	 */
	@Column(name="city")
	private String city;

	@Column(name="bill_day")
	private int billDay = 0;

	@Column(name="repayment_day")
	private int repaymentDay = 0;

	@Column(name="credit_blance")
	private BigDecimal creditBlance = BigDecimal.ZERO;

	@Column(name="user_name")
	private String userName;

	/**
	 * 银行编码
	 */
	@Column(name="bank_abbr")
	private String bankAbbr;

	/**银行卡名字*/
	@Column(name="bank_name")
	private String bankName;

	/**银行卡品牌*/
	@Column(name="bank_brand")
	private String bankBrand;

	/**卡的号码*/
	@Column(name="card_no")
	private String cardNo;

	/**联行号*/
	@Column(name="line_no")
	private String lineNo;

	/**安全码 信用卡后3位*/
	@Column(name="security_code")
	private String securityCode = "0";

	/**有效期*/
	@Column(name="expired_time")
	private String expiredTime = "0";//有效期

	/**预留手机号码*/
	@Column(name="phone")
	private String phone;

	/**身份证号*/
	@Column(name="id_card")
	private String idcard;


	/**卡名称*/
	@Column(name="card_type")
	private String cardType;


	/**对私还是对公帐户*/
	@Column(name="pri_or_pub")
	private String priOrPub = "0";

	/**
	 * 区别
	 * **/
	@Column(name="nature")
	private String nature;


	/**使用状态,0:已激活，1:删除*/
	@Column(name="state")
	private String state;


	/**是否默认结算卡*/
	@Column(name="is_def")
	private String idDef;


	/**logo*/
	@Column(name="logo")
	private String logo;

	/***绑卡类型**/
	@Column(name="type")
	private String type;

	/**创建时间*/
	@Column(name="create_time")
	@JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
	private Date   createTime;

	/**
	 * 银行英文简写
	 */
	@Column(name="abb_reviation")
	private String abbreviation;

	/**
	 * 信用卡额度
	 */
	@Column(name="quota")
	private String quota;

	/**
	 * 信用卡已用额度
	 */
	@Column(name="use_quota")
	private  String useQuota;

	/**
	 * 信用卡账单日
	 */
	@Column(name="statement_date")
	private String statementDate;

	/**
	 * 信用卡还款日
	 */
	@Column(name="repayment_date")
	private String repaymentDate;

	/**
	 * 1：银行卡支持畅捷通道，0：不支持
	 * 有商旅、新无卡
	 */
	@Transient
	private int CJFlag;

	/**
	 * 通道流水号
	 */
	@Column(name="request_No")
	private String requestNo;

	/**
	 * 银行卡图片地址
	 */
	@Column(name = "bank_card_photo", length = 254)
	private String bankCardPhoto;


	public int getId() {
		return id;
	}


	public void setId(int id) {
		this.id = id;
	}


	public long getUserId() {
		return userId;
	}


	public void setUserId(long userId) {
		this.userId = userId;
	}


	public String getBankName() {
		return bankName;
	}


	public void setBankName(String bankName) {
		this.bankName = bankName;
	}


	public String getBankBrand() {
		return bankBrand;
	}


	public void setBankBrand(String bankBrand) {
		this.bankBrand = bankBrand;
	}


	public String getCardNo() {
		return cardNo;
	}


	public void setCardNo(String cardNo) {
		this.cardNo = cardNo;
	}


	public String getLineNo() {
		return lineNo;
	}


	public void setLineNo(String lineNo) {
		this.lineNo = lineNo;
	}


	public String getSecurityCode() {
		return securityCode;
	}


	public void setSecurityCode(String securityCode) {
		this.securityCode = securityCode;
	}


	public String getExpiredTime() {
		return expiredTime;
	}


	public void setExpiredTime(String expiredTime) {
		this.expiredTime = expiredTime;
	}


	public String getPhone() {
		return phone;
	}


	public void setPhone(String phone) {
		this.phone = phone;
	}


	public String getCardType() {
		return cardType;
	}


	public void setCardType(String cardType) {
		this.cardType = cardType;
	}


	public String getNature() {
		return nature;
	}


	public void setNature(String nature) {
		this.nature = nature;
	}


	public String getState() {
		return state;
	}


	public void setState(String state) {
		this.state = state;
	}


	public Date getCreateTime() {
		return createTime;
	}


	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}


	public String getIdcard() {
		return idcard;
	}


	public void setIdcard(String idcard) {
		this.idcard = idcard;
	}


	public String getIdDef() {
		return idDef;
	}


	public void setIdDef(String idDef) {
		this.idDef = idDef;
	}


	public String getLogo() {
		return logo;
	}


	public void setLogo(String logo) {
		this.logo = logo;
	}


	public String getUserName() {
		return userName;
	}


	public void setUserName(String userName) {
		this.userName = userName;
	}


	public String getPriOrPub() {
		return priOrPub;
	}


	public void setPriOrPub(String priOrPub) {
		this.priOrPub = priOrPub;
	}


	public String getType() {
		return type;
	}


	public void setType(String type) {
		this.type = type;
	}


	public BigDecimal getCreditBlance() {
		return creditBlance;
	}


	public void setCreditBlance(BigDecimal creditBlance) {
		this.creditBlance = creditBlance;
	}


	public static long getSerialversionuid() {
		return serialVersionUID;
	}


	public int getBillDay() {
		return billDay;
	}


	public void setBillDay(int billDay) {
		this.billDay = billDay;
	}


	public int getRepaymentDay() {
		return repaymentDay;
	}


	public void setRepaymentDay(int repaymentDay) {
		this.repaymentDay = repaymentDay;
	}

	public String getAbbreviation() {
		return abbreviation;
	}

	public void setAbbreviation(String abbreviation) {
		this.abbreviation = abbreviation;
	}

	public String getQuota() {
		return quota;
	}

	public void setQuota(String quota) {
		this.quota = quota;
	}

	public String getUseQuota() {
		return useQuota;
	}

	public void setUseQuota(String useQuota) {
		this.useQuota = useQuota;
	}



	public String getBankBranchName() {
		return bankBranchName;
	}


	public void setBankBranchName(String bankBranchName) {
		this.bankBranchName = bankBranchName;
	}


	public String getProvince() {
		return province;
	}


	public void setProvince(String province) {
		this.province = province;
	}


	public String getCity() {
		return city;
	}


	public void setCity(String city) {
		this.city = city;
	}

	public String getStatementDate() {
		return statementDate;
	}

	public void setStatementDate(String statementDate) {
		this.statementDate = statementDate;
	}

	public String getRepaymentDate() {
		return repaymentDate;
	}

	public void setRepaymentDate(String repaymentDate) {
		this.repaymentDate = repaymentDate;
	}

	public int getCJFlag() {
		return CJFlag;
	}

	public void setCJFlag(int CJFlag) {
		this.CJFlag = CJFlag;
	}

	public String getBankAbbr() {
		return bankAbbr;
	}

	public void setBankAbbr(String bankAbbr) {
		this.bankAbbr = bankAbbr;
	}

	public String getRequestNo() {
		return requestNo;
	}

	public void setRequestNo(String requestNo) {
		this.requestNo = requestNo;
	}

	public String getBankCardPhoto() {
		return bankCardPhoto;
	}

	public void setBankCardPhoto(String bankCardPhoto) {
		this.bankCardPhoto = bankCardPhoto;
	}

	public void transformCardType() {
        String cardType = getCardType();
        if (Objects.equals(CommonConstants.DEBIT_2, cardType)) {
            setCardType(CommonConstants.DEBIT_CARD);
        }
        if (Objects.equals(CommonConstants.CREDIT_0, cardType)){
            setCardType(CommonConstants.CREDIT_CARD);
        }
    }

	@Override
	public String toString() {
		return "UserBankInfo{" +
				"id=" + id +
				", userId=" + userId +
				", bankBranchName='" + bankBranchName + '\'' +
				", province='" + province + '\'' +
				", city='" + city + '\'' +
				", billDay=" + billDay +
				", repaymentDay=" + repaymentDay +
				", creditBlance=" + creditBlance +
				", userName='" + userName + '\'' +
				", bankAbbr='" + bankAbbr + '\'' +
				", bankName='" + bankName + '\'' +
				", bankBrand='" + bankBrand + '\'' +
				", cardNo='" + cardNo + '\'' +
				", lineNo='" + lineNo + '\'' +
				", securityCode='" + securityCode + '\'' +
				", expiredTime='" + expiredTime + '\'' +
				", phone='" + phone + '\'' +
				", idcard='" + idcard + '\'' +
				", cardType='" + cardType + '\'' +
				", priOrPub='" + priOrPub + '\'' +
				", nature='" + nature + '\'' +
				", state='" + state + '\'' +
				", idDef='" + idDef + '\'' +
				", logo='" + logo + '\'' +
				", type='" + type + '\'' +
				", createTime=" + createTime +
				", abbreviation='" + abbreviation + '\'' +
				", quota='" + quota + '\'' +
				", useQuota='" + useQuota + '\'' +
				", statementDate='" + statementDate + '\'' +
				", repaymentDate='" + repaymentDate + '\'' +
				", CJFlag=" + CJFlag +
				", requestNo='" + requestNo + '\'' +
				", bankCardPhoto='" + bankCardPhoto + '\'' +
				'}';
	}
}
